package com.atguigu.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
@RequestMapping("servlet")
public class ServletController {
    /**
     * Servlet API的支持
     * 处理器(handler)的方法的参数中，直接添加Servlet中的接口即可
     * 方法中直接传递：HttpServletRequest，HttpServletResponse
     */
    @RequestMapping("servletParam")
    public void servletParam(ModelAndView modelAndView, HttpServletRequest request, HttpServletResponse response) throws IOException {
        //request获取客户端请求参数
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        System.out.println("username = " + username);
        System.out.println("password = " + password);
        System.out.println("默认支持Servlet的API");
        //response重定向到百度去
        response.sendRedirect("http://www.baidu.com");
    }
}
